$(function() {
        viewTh();
        $('.this-table').on('click', '.authorize-info', function() {
            setConfirm('是否确定盖章此项目？', function() {
                setAlert('已盖章');
                viewTable(1);
            })
        })

        $('.v-prev').click(function() {
            var $pageNum = $('.current-page')[0].value;
            if ($pageNum == 1) {
                setAlert('已至第一页');
            } else {
                $('.current-page')[0].value--;
                viewTable($('.current-page')[0].value);
                console.log($('.current-page')[0].value);
            }
        })

        $('.v-next').click(function() {
            var $pageNum = $('.current-page')[0].value;
            $('.current-page')[0].value++;
            viewTable($('.current-page')[0].value);
            console.log($('.current-page')[0].value);
        })
    })
    /**
     * [viewTh 显示表头]
     */
function viewTh() {
    //前端数据
    var modelName = "审定项目";
    //------------------------------------------------
    var options = getBASEGETAJAX();
    options.url = "epi/admin/view/columns/1";
    options.data.modelName = modelName;
    options.success = function(data) {
        console.log(data);
        var myTemplate = Handlebars.compile($("#th-template").html());
        console.log(myTemplate(data))
        $('.v-thead').html(myTemplate(data));
        viewTable();

    };
    options.error = function() {
        setAlert('系统繁忙，请刷新重试');
    };
    $.ajax(options);
}

/**
 * [viewTable 显示项目表格]
 * @param  {[int]} pageNum [页码]
 * @param  {[int]} records [每页记录数]
 */
function viewTable(pageNum, records) {
    //前端数据
    if (records == undefined) {
        records = 20;
    }
    var $viewTh = $('.view-th');
    var keyArr = []; //键名数组
    console.log($viewTh.length)
    for (var i = 0; i < $viewTh.length; i++) {
        keyArr.push($viewTh.eq(i).data('key'));
    }
    console.log(keyArr);
    loading();
    //------------------------------------------------
    var options = getBASEGETAJAX();
    options.url = "/tender/projects";
    options.success = function(data) {
        if (data != '') {
            var content = '';
            var k = keyArr[0];
            //遍历数据
            for (var i = 0; i < data.length; i++) {
                content += '<tr>';
                //遍历字段
                for (var j = 0; j < keyArr.length; j++) {
                    content += '<td>' + data[i].project[keyArr[j]] + '</td>';
                }
                content += '<th class="operate">' +
                    '<button class="drop-left">操作>></button>' +
                    '<div class="drop-left-menu">' +
                    '<li class="view-info" data-id="' + data[i].project.projectId + '">查看详情</li>' +
                    '<li class="authorize-info" data-id="' + data[i].project.projectId + '">项目盖章</li>' +
                    '</div>' +
                    '</th>';
                content += '</tr>';
            }
            $('.v-body').html(content);
        } else {
            setAlert('无更多数据');
            $('.current-page')[0].value--;
            viewTable($('.current-page')[0].value);
        }

        loadingHide();

    };
    options.error = function() {
        setAlert('系统繁忙，请刷新重试');
    };
    $.ajax(options);

}
v